package com.pearadmin.pro.modules.ser.rest;

import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.ser.domain.ServerDept;
import com.pearadmin.pro.modules.ser.domain.ServerInfo;
import com.pearadmin.pro.modules.ser.domain.dto.ServerDeptDto;
import com.pearadmin.pro.modules.ser.service.ServerDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Author: didiplus
 * Email: 972479352@qq.com
 * CreateTime: 2022/3/10
 * Desc:
 */
@Api(tags = {"服务器部门关联"})
@RestController
@RequestMapping(ControllerConstant.PREFIX + "serverdept")
public class ServerDeptController extends BaseController {


    @Resource
    ServerDeptService serverDeptService;
    /**
     * 新增字典值
     *
     * @param serverDeptDto 查询参数
     */
    @PostMapping("save")
    @Log(title = "新增部门主机关联数据数据")
    @ApiOperation(value = "新增部门主机关联数据数据")
    public Result save(@RequestBody ServerDeptDto serverDeptDto){
        List<ServerDept> list1= new ArrayList<ServerDept>();
        serverDeptDto.getServerIdList().forEach(item ->{
            ServerDept serverDept = new ServerDept();
            serverDept.setDeptId(serverDeptDto.getDeptId());
            serverDept.setServerId(item.toString());
            list1.add(serverDept);
        });
        return  auto(serverDeptService.saveBatch(list1));
    }


    /**
     * 新增字典值
     *
     * @param serverDeptDto 查询参数
     */
    @PostMapping("remove")
    @Log(title = "删除部门主机关联数据")
    @ApiOperation(value = "删除部门主机关联数据")
    public Result remove(@RequestBody ServerDeptDto serverDeptDto){
        return  auto(serverDeptService.delete(serverDeptDto));
    }
}
